package com.ykq.core.util;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: aaa-hospital-parent
 * @description:
 * @author: 闫克起
 * @create: 2024-05-21 16:36
 **/
public class WebUtil {
   //在任何springboot位置都可以获取request对象    @Autowire  HttpServletRequest request;
   public static HttpServletRequest getRequest(){
      ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
      HttpServletRequest request = sra.getRequest();
      return request;
   }

   public static String getToken(){
      return getRequest().getHeader("token");
   }

   public static String getUsername(){
      String token = getToken();
      return (String) JWTUtil.getInfo(token).get("username");
   }
}













